package com.hyh.admin.controller.resources;

import com.hyh.ad.common.core.controller.BaseController;
import com.hyh.ad.common.core.domain.AjaxResult;
import com.hyh.admin.domain.resources.Resources;
import com.hyh.admin.domain.resources.ResourcesDanmu;
import com.hyh.admin.service.IResourcesDanmuService;
import com.hyh.admin.service.IResourcesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/resources/danmu")
@Api(tags = "资源弹幕管理")
public class ResourcesDanmuController extends BaseController {
    @Autowired
    private IResourcesDanmuService resourcesDanmuService;


    /*
     * 添加弹幕
     */
    @PostMapping("/insert")
    @ApiOperation(value = "添加弹幕")
    public AjaxResult insert(@RequestBody ResourcesDanmu resourcesDanmu) {
        return toAjax(resourcesDanmuService.sendDanmu(resourcesDanmu));
    }

    /*
     * 删除弹幕
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除弹幕")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(resourcesDanmuService.deleteDanmu(id));
    }


    /*
     * 查询弹幕-资源ID
     */
    @GetMapping("/list/{resourceId}")
    @ApiOperation(value = "查询弹幕")
    public AjaxResult list(@PathVariable Long resourceId) {
        return AjaxResult.success(resourcesDanmuService.selectDanmu(resourceId));
    }

    /*
     * 查询弹幕 - 用户ID
     */
    @GetMapping("/listByUserId/{userId}")
    @ApiOperation(value = "查询弹幕")
    public AjaxResult listByUserId(@PathVariable Long userId) {
        return AjaxResult.success(resourcesDanmuService.selectDanmuByUserId(userId));
    }

    /*
     * 查询弹幕 - 资源ID和用户ID
     */
    @GetMapping("/listByResourceIdAndUserId/{resourceId}/{userId}")
    @ApiOperation(value = "查询弹幕")
    public AjaxResult listByResourceIdAndUserId(@PathVariable Long resourceId, @PathVariable Long userId) {
        return AjaxResult.success(resourcesDanmuService.selectDanmuByResourceIdAndUserId(resourceId, userId));
    }

    /*
     * 点赞弹幕
     */
    @PostMapping("/like/{id}")
    @ApiOperation(value = "点赞弹幕")
    public AjaxResult like(@PathVariable Long id) {
        return toAjax(resourcesDanmuService.likeDanmu(id));
    }
}
